package com.platform.modules.report.dto;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.platform.common.utils.NumberUtils;
import com.platform.common.utils.StringUtils;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Data
@ApiModel("报表查询参数")
public class BaseQueryDTO {

    @ApiModelProperty("省级")
    private String provinceNum;

    @ApiModelProperty("市级")
    private String cityNum;

    @ApiModelProperty("区县级")
    private String countyNum;

    @ApiModelProperty("查询年度，格式（三种）:2010| 2010,2011,2012 | 2010-2012,2015")
    private String years;

    @JsonIgnore
    private Date date;

    @ApiModelProperty("项目ID")
    private String prjId;






    /**
     * 用 sql 查询
     * @return
     */
    @JsonIgnore
    public List<String> getYearList(){
        List<String> data = new ArrayList<>();
        if(StringUtils.isNotBlank(years)){
            String[] years0 = years.split(",");
            for(String year1 : years0){
                if(year1.contains("-")){
                    String[] year2 = year1.split("-");
                    int startYear = NumberUtils.intValueOfNil(year2[0]);
                    int endYear = NumberUtils.intValueOfNil(year2[1]);
                    while(startYear <= endYear){
                        data.add( startYear++ + "");
                    }
                }else{
                    data.add(year1);
                }
            }
        }
        return data;
    }

}
